<?php
// 删除报名作品
namespace Beerus\Modules\DesignerCompetition2022\Actions;

use Doraemon\model\ReDesignerCompetition\Audit\DcAuditFirstResultHelper;
use Doraemon\model\ReDesignerCompetition\Audit\DcAuditFirstWorkHelper;
use Doraemon\model\ReDesignerCompetition\Audit\DcAuditFinalWorkHelper;
use Doraemon\model\ReDesignerCompetition\Audit\DcAuditFinalResultHelper;
use Doraemon\pockets\constInterface\Designer\DesignerCompetition2022;
use Illuminate\Http\Request;
use Encore\Admin\Actions\RowAction;

class WorkBatchDelete extends RowAction implements DesignerCompetition2022{
    public $name = '从所有评审池中移除';
    public $oWork = null;
    public $oResult = null;

    public function __construct($iAuditStep = 1) {
        parent::__construct();
        if ($iAuditStep == self::AUDIT_STEP_FIRST) {
            $this->oWork = (DcAuditFirstWorkHelper::getInstance());
            $this->oResult = (DcAuditFirstResultHelper::getInstance());
        } else {
            $this->oWork = (DcAuditFinalWorkHelper::getInstance());
            $this->oResult = (DcAuditFinalResultHelper::getInstance());
        }
    }

    public function handle($iId) {
        $aWorkItem = $this->oWork->getItemById($iId);
        // 从评审池中移除
        $this->oWork->batchUpdateDataStatus2DelByCondition(['sign_id'=>$aWorkItem['sign_id']]);
        // 从评审表移除
        $this->oResult->batchUpdateDataStatus2DelByCondition(['sign_id'=>$aWorkItem['sign_id']]);
        return $this->response()->success('移除成功')->refresh();
    }

    public function retrieveModel(Request $request) {
        if (!$key = $request->get('_key')) {
            return false;
        }
        return $key;
    }

    public function dialog() {
        $this->confirm('确定将该作品移除评审池？');
    }
}
